package org.jsets.fastboot.security.config;

import org.springframework.boot.CommandLineRunner;
import org.springframework.security.crypto.password.PasswordEncoder;
import lombok.extern.slf4j.Slf4j;
import org.jsets.fastboot.security.ICaptchaProvider;
import org.jsets.fastboot.security.IUserInfoProvider;
import org.jsets.fastboot.security.SecurityUtils;
import org.jsets.fastboot.security.authc.IAuthenticator;
import org.jsets.fastboot.security.authc.LoginHandlerManager;
import org.jsets.fastboot.security.authz.AuthzRuleManager;
import org.jsets.fastboot.security.authz.IAuthorizer;
import org.jsets.fastboot.security.cache.ICacheManager;
import org.jsets.fastboot.security.listener.IListenerManager;
import org.jsets.fastboot.security.online.OnlineManager;
import org.jsets.fastboot.security.rememberme.RememberMeManager;
import org.jsets.fastboot.security.token.ITokenManager;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
public class SecurtityCommandLineRunner implements CommandLineRunner {

	@Autowired
	private IListenerManager listenerManager;
	@Autowired
	private LoginHandlerManager loginHandlerManager;
	@Autowired
	private AuthzRuleManager authzRuleManager;
	@Autowired
	private ICacheManager cacheManager;
	@Autowired
	private ITokenManager tokenManager;
	@Autowired
	private ICaptchaProvider captchaProvider;
	@Autowired
	private IUserInfoProvider userInfoProvider;
	@Autowired
	private PasswordEncoder passwordEncoder;
	@Autowired
	private IAuthenticator authenticator;
	@Autowired
	private IAuthorizer authorizer;
	@Autowired
	private RememberMeManager rememberMeManager;
	@Autowired
	private OnlineManager onlineManager;

	@Override
	public void run(String... args) throws Exception {
		log.info("Security组件启动");
		
		this.listenerManager.afterInitialize();
		this.loginHandlerManager.afterInitialize();
		this.authzRuleManager.afterInitialize();
		this.cacheManager.afterInitialize();
		
		SecurityUtils.setUserInfoProvider(this.userInfoProvider);
		SecurityUtils.setCacheManager(this.cacheManager);
		SecurityUtils.setTokenManager(this.tokenManager);
		SecurityUtils.setCaptchaProvider(this.captchaProvider);
		SecurityUtils.setPasswordEncoder(this.passwordEncoder);
		SecurityUtils.setAuthenticator(this.authenticator);
		SecurityUtils.setAuthorizer(this.authorizer);
		SecurityUtils.setRememberMeManager(rememberMeManager);
		SecurityUtils.setOnlineManager(onlineManager);
	}

}